"""
FileName：settings.py
Description：
Author：gaojiahui
Time：2025/8/18 20:09
Website：https://gitee.com/gao-jiahui
"""
import os
from pathlib import Path

from dotenv import load_dotenv

# 加载环境变量
load_dotenv()

# 项目根目录
BASE_DIR = Path(__file__).resolve().parent.parent

class Settings:
    # API配置
    BASE_URL = os.getenv("BASE_URL", "http://127.0.0.1:9999")
    API_TIMEOUT = int(os.getenv("API_TIMEOUT", 10))

    # 认证配置
    CLIENT_ID = os.getenv("CLIENT_ID", "pig")
    CLIENT_SECRET = os.getenv("CLIENT_SECRET", "pig")
    ADMIN_USER = os.getenv("ADMIN_USER", "admin")
    ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD", "YehdBPev")
    CAPTCHA_MODE = os.getenv("CAPTCHA_MODE", "fixed")
    FIXED_CAPTCHA = os.getenv("FIXED_CAPTCHA", "8888")

    # 通知配置
    NOTIFICATION_ENABLED = os.getenv("NOTIFICATION_ENABLED", "false").lower() == "true"
    DINGTALK_WEBHOOK = os.getenv("DINGTALK_WEBHOOK", "https://oapi.dingtalk.com/robot/send?access_token=f175122eaa78237f8395ad776d2c624581f3f2b5392d2b2e5063d7b7cc80cbbd")
    DINGTALK_SECRET = os.getenv("DINGTALK_SECRET", "SEC64bc45b28a56c6458cbcd2948dd3b97b3b87b7aeeee81309324fa6ebb23d8cc5")

    # 数据库配置
    DB_HOST = os.getenv("DB_HOST", "localhost")
    DB_PORT = int(os.getenv("DB_PORT", 3306))
    DB_USER = os.getenv("DB_USER", "root")
    DB_PASSWORD = os.getenv("DB_PASSWORD", "root")
    DB_NAME = os.getenv("DB_NAME", "pig")

    # 测试配置
    TEST_USER_PREFIX = "test_user_"
    TEST_PASSWORD_PREFIX = "test"
    TEST_ROLE_PREFIX = "测试角色_"
    TEST_DEPT_PREFIX = "测试部门_"

    # 路径配置
    LOG_DIR = BASE_DIR / "logs"
    ALLURE_DIR = BASE_DIR / "allure-results"
    SCREENSHOT_DIR = BASE_DIR / "screenshots"
    DATA_DIR = BASE_DIR / "test_data"

    # 数据驱动配置
    DATA_DRIVER_ENABLED = os.getenv("DATA_DRIVER_ENABLED", "true").lower() == "true"
    TEST_DATA_FORMAT = os.getenv("TEST_DATA_FORMAT", "excel")   # excel, json, yaml
    TEST_DATA_DIR = BASE_DIR / "test_data" / "test_cases"
    TEST_DATA_TEMPLATE_DIR = BASE_DIR / "test_data" / "templates"

    # 数据验证配置
    DATA_VALIDATION_ENABLED = os.getenv("DATA_VALIDATION_ENABLED","true").lower() == "true"
    STRICT_VALIDATION = os.getenv("STRICT_VALIDATION", "false").lower() == "true"

    # 动态数据生成配置
    DYNAMIC_DATA_ENABLED = os.getenv("DYNAMIC_DATA_ENABLED", "true").lower() == "true"
    DYNAMIC_DATA_PREFIX = os.getenv("DYNAMIC_DATA_PREFIX", "auto_")

    # 创建必要目录
    for directory in [LOG_DIR, ALLURE_DIR, SCREENSHOT_DIR, DATA_DIR]:
        directory.mkdir(exist_ok=True)

settings = Settings()